package com.ruoyi.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.entity.Order;
import com.ruoyi.mapper.OrderMapper;
import com.ruoyi.service.IOrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.vo.PageResult;
import com.ruoyi.vo.order.OrderPageVo;
import com.ruoyi.vo.order.OrderQueryVo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 《智慧停车系统》--订单表 服务实现类
 * </p>
 *
 * @author 贾玉亮
 * @since 2022-11-14
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements IOrderService {

    @Resource
    private OrderMapper orderMapper;

    @Override
    public PageResult<OrderPageVo> queryOrderList(OrderQueryVo orderQueryVo) {
        PageHelper pageHelper = new PageHelper();
        Page<OrderPageVo> pageVos = pageHelper.startPage(orderQueryVo.getPage(), orderQueryVo.getSize()).doSelectPage(() -> orderMapper.queryOrderList(orderQueryVo));
        PageResult<OrderPageVo> result = new PageResult<>();
        result.setTotal(pageVos.getTotal());
        result.setResults(pageVos.getResult());
        return result;
    }

//    private List<OrderPageVo> listFoVos(List<Order> list){
//        List<OrderPageVo> vos = new ArrayList<>();
//        for (Order order : list) {
//            OrderPageVo vo = new OrderPageVo();
//            BeanUtils.copyProperties(order,vo);
//            vos.add(vo);
//        }
//        return vos;
//    }
}
